package com.qk.management.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qk.dto.activity.ActivityDTO;
import com.qk.entity.Activity;
import com.qk.management.annotation.LogAnno;
import com.qk.management.mapper.ActivityMapper;
import com.qk.management.service.ActivityService;
import com.qk.result.PageResult;
import com.qk.vo.activity.ActivityQueryVO;
import com.qk.vo.activity.ActivityVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author:zhengbowen
 * @Date: 2025/10/10 19:58
 * @Description: 活动业务逻辑
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class ActivityServiceImpl implements ActivityService {

    private final ActivityMapper activityMapper;

    @LogAnno
    @Override
    public void deleteBatchActivities(List<Integer> ids) {
        activityMapper.deleteBatchActivities(ids);
    }
    @LogAnno
    @Override
    public void deleteActivity(Integer id) {
        activityMapper.deleteActivity(id);
    }

    @Override
    public List<ActivityVO> selectActivityListByType(Integer type) {
        return activityMapper.selectActivityListByType(type);
    }
    @LogAnno
    @Override
    public void insertActivity(Activity activity) {
        activity.setCreateTime(LocalDateTime.now());
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.insertActivity(activity);
    }

    @Override
    public List<ActivityVO> selectActivityList() {
        return  activityMapper.selectActivityList();
    }
    @LogAnno
    @Override
    public void updateActivity(Activity activity) {
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.updateActivity(activity);
    }

    @Override
    public ActivityVO selectActivityById(Long id) {
        return activityMapper.selectActivityById(id);
    }

    @Override
    public PageResult<ActivityQueryVO> selectActivitiesByPage(ActivityDTO activityDto) {
        PageHelper.startPage(activityDto.getPage(), activityDto.getPageSize());
        List<ActivityQueryVO>  activityVOList = activityMapper.selectActivitiesByPage(activityDto);
        PageInfo<ActivityQueryVO> pageResult = new PageInfo<>(activityVOList);
        return PageResult.<ActivityQueryVO>builder()
                .total(pageResult.getTotal())
                .rows(pageResult.getList())
                .build();
    }
}
